/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/
#ifndef SQLTEXTEDIT_H
#define SQLTEXTEDIT_H

#include <QTextEdit>
#include <QSqlRecord>
#include "win32def.h"

/**
	@author BogDan Vatra <taipan@omnidatagrup.ro>
*/
namespace SQL
{class Query;}

class KONTAMABIL_EXPORTS TextEdit : public QTextEdit
{
	Q_OBJECT
	Q_PROPERTY(QString queryName READ queryName WRITE setQueryName)
	Q_PROPERTY(QString fieldName READ fieldName WRITE setFieldName)
	Q_PROPERTY(bool toPlainText READ isPlainText WRITE setToPlainText)

public:
	TextEdit(QWidget *parent = 0);

	~TextEdit();

	const QString & queryName();
	void setQueryName(const QString & queryName);

	const QString & fieldName();
	void setFieldName(const QString & fieldName);

	bool isPlainText();
	void setToPlainText(bool plainText);

signals:
	void ctrlReturnPressed();
	void escapePressed();
	void focusIn();
	void focusOut();

protected:
	void keyPressEvent(QKeyEvent * event);
	void focusInEvent(QFocusEvent * event);
	void focusOutEvent(QFocusEvent * event);

private slots:
	void recordChanged(const QSqlRecord&);
	void setReadWrite();
	void setReadOnly();
	void bindValue();

private:
	bool m_plainText;
	QString m_queryName;
	QString m_fieldName;
	SQL::Query * m_query;
};

#endif
